/*
	File: data/scripts/physics_trigger-parenting.nut
	Author: GameStart3d.com
*/

/*!
	@short	PhysicsCubeItem
	@author	GameStart3d.com
*/
class	PhysicsCubeItem
{
	/*!
		@short	OnUpdate
		Called during the scene update, each frame.
	*/
	function	OnUpdate(item)
	{
	}

	function	OnPhysicStep(item, dt)
	{
		ItemApplyLinearForce(item, Vector(1,0,0).Scale(25.0 * ItemGetMass(item)))
	}

	/*!
		@short	OnSetup
		Called when the item is about to be setup.
	*/
	function	OnSetup(item)
	{
		ItemPhysicSetLinearFactor(item, Vector(1,0,1))
	}
}

class	TestItem
{
	item_to_follow	=	0
	item_trigger	=	0

	function	OnSetup(item)
	{
		item_to_follow = SceneFindItem(g_scene, "PhysicsCubeItem")
		item_trigger = ItemCastToTrigger(SceneFindItem(g_scene, "Trigger"))
	}

	function	OnUpdate(item)
	{
		local	pos = ItemGetPosition(item_to_follow) + Vector(0,4,0)
		ItemSetPosition(item, pos)

		local	str = ""
		if (!TriggerTestItem(item_trigger, item))
			str = "Item is NOT in trigger"
		else
			str = "Item is in trigger :)"

		ItemGetScriptInstanceFromIndex(item, 1).label = str

	}
}
